package com.wms.web.action.system;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.wms.data.domain.service.MenuService;
import com.wms.web.action.AbstractAction;

@ParentPackage("wms")
@Namespace("/app")
@Result(name="exception", location="/WEB-INF/jsp/common/error.jsp")
@ExceptionMappings(@ExceptionMapping(exception="java.lang.Exception", result="exception"))
public class MenuListAction extends AbstractAction {

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private MenuService menuService;

	@Action(value="getMenuJsonData")
	public String ajaxGetJsonData() {
		
		try {
			
			String pid = getParameter("pid");
			
			if (StringUtils.isBlank(pid)) {
				
				httpWrite(20, menuService.getMainMenu());
			}
			else {
				
				httpWrite(20, menuService.getListByPID(pid));
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
}